#include "list.h"

void List::add ( Listable * listable ) {     //#D
   ListNode *newone = new ListNode ( 0, *listable, list );  //we add it to the top
   list = newone;
}

Listable * List::listIter () {    //#D
   return advanceHead( &iterator );
}

Listable* List::advanceHead ( ListNode** head ) {
   Listable* ret;
   if ( *head == 0 ) 
      return 0; 
   else {
      ret = (*head)->part;
      *head = (*head)->next;
      return ret;
   }
}

// iters two iterators
Listable** List::doubleIter (Listable** start) {       //#D
   Listable *a,*b;

   //pDebug ( "doubleIter: " << iterator << " " << iteratorB );
   
   if ( iteratorB == 0 ) {
      a=b=0;
   } else {
      b = iteratorB->part;
      iteratorB = iteratorB->next;
      a = iterator->part;
      if ( iteratorB == 0 ) {
	 iterator = iterator->next;
	 if ( iterator != 0 ) {
	    iteratorB = iterator->next;
	 } 
      } 
   }
   start[0] = a;
   start[1] = b;
   return start; 
}

//#undef 0
